package top.truehaku.generator.code.domain.model.column;

import lombok.Getter;
import lombok.Setter;
import top.truehaku.generator.common.domain.ValueObject;
import top.truehaku.generator.common.enums.JavaType;
import top.truehaku.generator.common.util.StringUtils;


public class ColumnType implements ValueObject<ColumnType> {

    @Getter@Setter
    private String columnType;

    public ColumnType(String columnType) {
        this.columnType = columnType;
    }

    @Override
    public boolean sameValueAs(ColumnType other) {
        return other!=null&&this.columnType.equals(other.columnType);
    }

    public String getSimpleType(){
       return StringUtils.subBefore(columnType, '(', false);
    }

    public JavaType getJavaType(){
        return JavaType.getJavaType(this.getSimpleType());
    }

    public static void main(String[] args) {
        ColumnType columnType = new ColumnType("varchar(64)");
        String simpleType = columnType.getSimpleType();
        System.out.println(simpleType);
        System.out.println(byte[].class.getTypeName());
    }

}
